package com.jming.jike.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * swagger配置
 *
 * @author jming
 */
@Data
@Configuration
@EnableSwagger2
@ConfigurationProperties(prefix = "swagger")
public class SwaggerConfig {

    private Boolean enable;
    private String title;
    private String version;
    private String name;
    private String url;
    private String email;
    private String auth;

    @Bean
    public Docket createRestApi() {

        Docket docket;
        if (enable) {
            docket = new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(new ApiInfoBuilder().title(title)
                            .description("极客外卖接口").version(version)
                            .contact(new Contact(name, url, email))
                            .build()).select().apis(RequestHandlerSelectors.basePackage("com.jming"))
                    .paths(PathSelectors.any()).build();

        } else {
            docket = new Docket(DocumentationType.SWAGGER_2).enable(false);
        }
        return docket;
    }

}
